package com.obas.components {
    import com.ease.core.components.StageWindow;
    import com.ease.core.events.PerspectiveEvent;
    import com.ease.core.managers.PerspectiveManager;
    import com.ease.util.MruCache;
    import com.ease.framework.ViewRegistry;
    import com.ease.model.term.CoolPerspective;

    import mx.core.UIComponent;
    import mx.events.FlexEvent;

    [Event(name="{com.ease.core.events.PerspectiveEvent.REQUEST_ID}", type="com.ease.core.events.PerspectiveEvent")]
    public class AppStageWindow extends StageWindow {
        public var perspective:String;

        public function AppStageWindow() {
            super();
            addEventListener(FlexEvent.CREATION_COMPLETE, createComplete);
        }

        private function createComplete(e:*):void {
            ViewRegistry.instance.eventBus.addParticipant(this);
            openPerspective(perspective);
        }

        override public function openPerspective(perspective:String):void {
            this.stageWindowBar.clearViewWindows();
            PerspectiveManager.getInstance().activePerspective = perspective;

            var layoutXml:XML = XML((PerspectiveManager.getInstance().getActivePerspective() as CoolPerspective).layout).layout[0];
            buildPerspective(layoutXml, UIComponent(this), perspective);
            dispatchEvent(new PerspectiveEvent(perspective, null, PerspectiveEvent.TYPE_OPENED));
        }
    }
}